//
//  OO_DetailViewController.m
//  ShopProject
//
//  Created by macbookpro on 2018/9/26.
//  Copyright © 2018年 ShopProject. All rights reserved.
//

#import "OO_DetailViewController.h"
#import "SDCycleScrollView.h"
#import "OO_OrderViewController.h"
#import "OO_ChooseView.h"
//#import "OO_OrderViewController"
@interface OO_DetailViewController ()<SDCycleScrollViewDelegate>
@property (weak, nonatomic) IBOutlet UIView *bannerView;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UILabel *nameLable;
@property (weak, nonatomic) IBOutlet UILabel *descripLable;
@property (weak, nonatomic) IBOutlet UILabel *moneyLable;
@property (weak, nonatomic) IBOutlet UIImageView *detailImageViewOne;
@property (weak, nonatomic) IBOutlet UIImageView *detailImageViewTwo;
@property (weak, nonatomic) IBOutlet UILabel *saleLable;
@property (weak, nonatomic) IBOutlet UILabel *postMoneyLable;
//@property (nonatomic,strong) OO_ChooseView *chooseView;
@end

@implementation OO_DetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"商品详情";
    if (@available(iOS 11.0, *)) {
        _scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    


    [self initViews];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


#pragma mark - Event

- (IBAction)buyButtonPress:(UIButton *)sender {
    
    if (![CommonAPI userLoginStatus]) {
        
        [MBProgressHUD showTipMessageInView:PLEASELOGINSTR];
        
        return;
    }
    
   OO_ChooseView *chooseView = [OO_ChooseView loadFromNib];
    WeakSelf
    chooseView.chooseSuccessBlock = ^(OO_OrderModel * _Nonnull model) {
        OO_OrderViewController *VC = [OO_OrderViewController new];
        VC.orderModel = model;
        [weakSelf.navigationController pushViewController:VC animated:1];
    };
    chooseView.model  = self.model;
    [[UIApplication sharedApplication].delegate.window addSubview:chooseView];
    
}
- (IBAction)shopCarButtonPress:(UIButton *)sender {
    
    if (![CommonAPI userLoginStatus]) {
        
        [MBProgressHUD showTipMessageInView:PLEASELOGINSTR];
        
        return;
    }
    
    OO_ChooseView *chooseView = [OO_ChooseView loadFromNib];
    chooseView.shopCar = YES;
//    WeakSelf
//    chooseView.chooseSuccessBlock = ^(OO_OrderModel * _Nonnull model) {
//        OO_OrderViewController *VC = [OO_OrderViewController new];
//        VC.orderModel = model;
//        [weakSelf.navigationController pushViewController:VC animated:1];
//    };
    chooseView.bottomButton.backgroundColor = RGB(51, 51, 51, 1);
    [chooseView.bottomButton setTitle:@"添加到购物车" forState:0];
    chooseView.model  = self.model;
    [[UIApplication sharedApplication].delegate.window addSubview:chooseView];
    
    
}
#pragma mark - UI
-(void)initViews{

    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH) shouldInfiniteLoop:YES imageNamesGroup:nil];
    cycleScrollView.imageURLStringsGroup = self.model.image;
    cycleScrollView.delegate = self;
    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    cycleScrollView.bannerImageViewContentMode =  UIViewContentModeScaleAspectFill;
    [self.bannerView addSubview:cycleScrollView];

    self.nameLable.text = self.model.goodsName;
    self.descripLable.text = self.model.describe;
    self.moneyLable.text = [NSString stringWithFormat:@"¥%.2lf",self.model.price];
    self.saleLable.text = [NSString stringWithFormat:@"已售%ld",self.model.soldCount];
    NSString *image0 = @"";
    NSString *image1 = @"";
    if (self.model.detailImage.count > 0) {
        image0 = self.model.detailImage[0];
    }
    if (self.model.detailImage.count > 1) {
        image1 = self.model.detailImage[1];
    }
    
    [self.detailImageViewOne sd_setImageWithURL:[NSURL URLWithString:image0] placeholderImage:[UIImage imageNamed:IMAGEPLACEHOLDER]];
    
    [self.detailImageViewTwo sd_setImageWithURL:[NSURL URLWithString:image1] placeholderImage:[UIImage imageNamed:IMAGEPLACEHOLDER]];
    
    
    self.postMoneyLable.text = [NSString stringWithFormat:@"快递费：%.2lf元",POSTMONEY];

}

@end
